//
//  ZZInputViewController.m
//  ZZInputView
//
//  Created by 郑程旭 on 2022/2/19.
//  Copyright © 2022 qq282424020. All rights reserved.
//

#import "ZZInputViewController.h"
#import "ZZInputView.h"

#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>

@interface ZZInputViewController () <ZZInputViewDelegate,ZZInputViewDataSource,UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (nonatomic, strong) UIImagePickerController *imagePickerController;


@end

@implementation ZZInputViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

- (UIImagePickerController *)imagePickerController {
    if (_imagePickerController == nil) {
        _imagePickerController = [[UIImagePickerController alloc] init];
        _imagePickerController.delegate = self;
    }
    return _imagePickerController;
}

#pragma mark - ZZInputViewDataSource
//设置选中图片
- (UIImage *)inputViewFinishedSelectedPhoto {
    return [[UIImage alloc] init];
}

#pragma mark - ZZInputViewDelegate
//选择相册
- (void)inputViewSelectPhotoLibrary {
    NSLog(@"选择相册");
    [(ZZInputView *)self.view reloadData];

}

//选择相机
- (void)inputViewSelectTakePhoto {
    NSLog(@"选择相机");
    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (status == AVAuthorizationStatusNotDetermined) {
        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
            if (granted) {
                [self takePhoto];
            }
        }];
    } else if (status == AVAuthorizationStatusDenied || status == AVAuthorizationStatusRestricted) {

    } else {
        [self takePhoto];
    }

}

//选择录制语音
- (void)inputViewSelectRecordVoice {
    NSLog(@"选择录制语音");

}

#pragma mark - 打开相机
- (void)takePhoto {
    dispatch_async(dispatch_get_main_queue(), ^{
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:self.imagePickerController animated:YES completion:^{

            }];
        }
    });
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
    
}




@end
